/*
 * 版权所有(c)  1952110078@qq.com  2022 - 2022
 */

package com.ldc.commonlibs.common;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.ObservableTransformer;
import io.reactivex.rxjava3.core.SingleTransformer;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * @author liudc
 * @since 2022/7/8 22:14
 */
public class RxHelper {

    /**
     * 切换线程：io线程执行耗时操作，主线程执行UI操作
     */
    public static <T> ObservableTransformer<T, T> observableSchedulers() {
        return observable -> observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    /**
     * 线程切换
     *
     * @param <T>
     * @return
     */
    public static <T> SingleTransformer<T, T> singleSchedulers() {
        return observable -> observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
